#include<iostream>
#include<ostream>
#include <pthread.h>
using std::cout;
using std::endl;
using std::ostream;
class Point{
public:
    static void creat(){
        _point = new Point(1,2);
        atexit(destory);
    }
    static Point* Instance(){
        pthread_once(&once_con,creat);
        return _point;
    }
    void init(int x, int y){
        _x = x;
        _y = y;
    }
    friend
    ostream& operator<<(ostream &ofs,const Point &rhs);
    //问 为啥+static 就可以了
    //Point::destory  Point::void(*)
    static void destory(){
        cout<<"this is destory"<<endl;
        if(_point){
        delete _point;
         _point = nullptr;
        }
    }
private:
    Point(int x,int y)
    :_x(x)
    ,_y(y)
    {}
    ~Point(){
        cout<<"~point"<<endl; //为什么写了destory 不写析构了 因为会陷入死循环
    }
    Point(const Point&rhs) = delete;
    Point& operator= (const Point&rhs) = delete;
private:
    int _x;
    int _y;
    static Point* _point;
    static pthread_once_t once_con;
};
Point* Point::_point = nullptr;
pthread_once_t Point::once_con = PTHREAD_ONCE_INIT;
//<<
ostream& operator<<(ostream &ofs,const Point &rhs){
    ofs<<"Point :"<<rhs._x<<" "<<rhs._y;
    return ofs;
}
int main(void){
    Point *p = Point::Instance();  
}